<?php 

require "sphinxapi.php";
require "Mysql.class.php";

$db = Mysql::getInstance();
$sp =  new SphinxClient();

$sp->setServer("127.0.0.1",9312);

$sp->SetArrayResult(true);
$sp->setMatchMode(SPH_MATCH_ANY);
$sp->SetLimits(10,30);


$index ="test";
$res = $sp->Query("华为",$index);
//var_dump($res);


foreach ($res["matches"] as $vo) {


	$sql = "select id,title,date,source from article where id=".$vo['id'];

	$total = mysqli_num_rows($sql);//总记录数
	echo $total;exit;
  	$page = 1;//当前页
  	// 每页记录数
	$every = 5;
	$pages = ceil($total/$every);//总页数
   //判断有没有点击上一页或者下一页
  	if(isset($_GET['page'])){
  		//当前页就是闯过的page的值
  		$page = $_GET['page'];
  	}
  	//当前页如果大于总页数就等于当前页
  	if($page > $pages){
  		$page = $pages;
  	}
  	//当前页小于1时就等于第一页
  	if($page < 1){
  		$page = 1;
  	}// 计算每页的limit的起始位置
  	$start = ($page-1) * $every;
  	$sql .= " limit {$start},$every";
  	$info[] = $db->fetch($sql);

}



//print_r($arr);
// f:
//cd webserver\coreseek\bin
//indexer -c ../sphinx.conf test
//searchd -c ../sphinx.conf


?>
<!DOCTYPE HTML >
<html>
 <head>
  <title> 用户中心 </title>
  <meta charset="utf-8">
  <style>
	*{margin:0px;padding:0px}
	table{margin:20px auto}
	.so{width:400px;margin:30px auto}
	.so div{height:40px;line-height:40px}
	.so div span{display:inline-block;width:80px}
	input[name=sub]{width:105px;height:30px}
  </style>
 </head>

 <body>
	<table border=1 cellspacing=0 width="600px">
		<tr height="40px" align="center">
			<td width="10%">编号</td>
			<td width="40%">标题</td>
			<td width="30%">时间</td>
			<td width="20%">来源</td>
		</tr>
		<?php foreach($info as $vo){?>
		<tr align="center" height="40px">
			<td><?=$vo['id'] ?></td>
			<td><?=$vo['title'] ?></td>
			<td><?=$vo['date'] ?></td>
			<td><?=$vo['source'] ?></td>
		</tr>
		<?php };?>
		<tr height="40px" align="center">
			<td colspan=6>
				<a href="./index.php?page=<?= ($page-1).(isset($url)?$url:"")?>">上一页</a>&nbsp;&nbsp;
				第<?=$page?>页/共<?=$pages ?>页&nbsp;&nbsp;
				<a href="./index.php?page=<?= ($page+1).(isset($url)?$url:"")?>">下一页</a>
			</td>
		</tr>
	</table>
 </body>
</html>
